import bianliang from "./bianliang.js";

class Bullet {
	constructor(x, y) {
	    this.x = x;
		this.y = y;
		this.img = bianliang.resObj[2];
		this.width = this.img.width / 6.25;
		this.height = this.img.height / 6.25;
	}
	
	draw(ctx) {
		this.move();
		ctx.drawImage(this.img, this.x, this.y, this.width, this.height);
	}
	
	move() {
		this.y -= 40;
		//当子弹飞出屏幕之后就要移除这颗子弹
		if (this.y <= -100) {
			//找出这颗子弹的索引
			var index = bianliang.bulletList.indexOf(this);
			bianliang.bulletList.splice(index, 1);	//替换当前的元素，相当于删除
		}
	}
}

export default Bullet;